export default {


	data(){
		return {
			divScrollTop:0
		}
	},
	created(){
		
	},

	activated() {
		this.$store.commit('setMenuShow', false);
		var divBody = this.getBodyEl();
		if(divBody){
			divBody.scrollTop = this.divScrollTop;
		}
	},

    deactivated(){
		var divBody = this.getBodyEl();
		if(divBody){
			this.divScrollTop = divBody.scrollTop;
		}	
    },

	mounted(){
		let tthis = this,
			divScrollDom = tthis.$refs.divScroll;
		if(divScrollDom){
			divScrollDom.addEventListener('scroll',function(e){
				let scrollTop = divScrollDom.scrollTop,
					scrollHeight = divScrollDom.scrollHeight,
					clientHeight = divScrollDom.clientHeight;
				if(tthis.onScroll){
					tthis.onScroll(divScrollDom);
				}
				if(tthis.onScrollBottom){
					if((scrollTop+clientHeight + 100) > scrollHeight){
						tthis.onScrollBottom();
					}
				}
				// console.log(scrollHeight)
				// console.log(scrollTop+clientHeight)
			})
		}
	},

	methods: {

		getBodyEl(){
			let nodes = this.$el.childNodes,
				nodeClass;
			for(let i = 0; i<nodes.length; i++){
				nodeClass = nodes[i].className;
				if(nodeClass && nodeClass.indexOf('body') > -1){
					return nodes[i];
				}
			}
		},
		toPage(name){
			this.$router.push({
				name: name
			})
		},
		toUserProfile(name) {
			var userInfo = this.$store.state.user.userInfo;
			if (name == userInfo.loginname || typeof name == 'object') {
				name = userInfo.loginname;
			}
			this.$router.push({
				name: 'userProfile',
				query: {
					name: name
				}
			})
		},
		toTopic(id) {
			console.log(id,11)
			this.$router.push({
				name: 'topic',
				query: {
					id: id
				}
			})
		}
	},
}
